define(['jquery','api','user','util'],function($,api,user,util){
	var vm,
	   time,
	   startid,
	   ORDER_STATUS={'49':'未成交','50':'已成交','51':'已撤单','54':'部分撤单','55':'部分成交'};
	   
	var controller = {
	   init:function(id){
	   	   if(!user.checkLogin())return;
	   	   	api.headerShow(1);
			api.headerTitle(L('html_title_order_ltrecord'));
		   api.setTitle(L('html_title_order_ltrecord'));	
		   this.render();
	   },
	   render:function(){
	   	  var that=this;
	   	  	$('#common').html('<div id="orderLtRecord"></div>');

	       require(['text!pages/order/ltrecord.html','Vue'],function(tpl,Vue){
	            vm=new Vue({
	               el:'#orderLtRecord',
	               data:{
	               	  show:true,
	               	  ordersHistory:[], // 历史列表数据容器
	               	  loading:false,
	                    startTime:(function(d){return d.format('yyyy-MM-dd')})(new Date(new Date().getTime()-86400*1000)),
	                    endTime:(function(d){return d.format('yyyy-MM-dd')})(new Date()),
	                    form:{
	                    	startTime:'',
	                    	endTime:''
	                    },
	                    showMore:{ // 显示更多
	                          today:false,
	                          history:false
	                    },
	                    noMore:false
	               },
	               filters:{
	               		direct:function(v){
	       	         		if(v==98) return '买入';
	       	         		if(v==115) return '卖出';
	       	         	},
		               	status:function(v){
	       	         		return ORDER_STATUS[v]?ORDER_STATUS[v]:'';
		       	         },
		       	         priceFormat:function(v,mindecimal){
		       	         	return util.priceFormat(mindecimal,v);
		       	         }
	              },
	               methods:{
	                 showDetail:function(opensn,o){
	                 	api.setOrder(o);
				 	    location.hash="#/order/historydetail/"+opensn; // 20161209dyx
				 	 },
				 	 query:function(more){
				 	    if(more === undefined){
			                this.ordersHistory=[];
			                startid=0;
			            }
				 	    
			            if(this.form.startTime==''){
			            	this.form.startTime = this.startTime;
			            }
			            if(this.form.endTime==''){
							this.form.endTime = this.endTime;            	
			            }
			            that.load();
				 	 }
	               },
	               template:tpl
	            });
	       })
	   },
	   load:function(){
			vm.loading = true;
            var orders,
            	pageSize=20;
	   	   var params={begindate:vm.form.startTime,enddate:vm.form.endTime,id:startid,count:pageSize,sort:50};
	   	   api.ltOrdersHis(params,function(rs){
                vm.loading = false;
               if(rs.retcode=='0' && rs.data){
               		vm.noMore=false;
                    orders=rs.data;
                    vm.ordersHistory=vm.ordersHistory.length?vm.ordersHistory.concat(orders):orders;
                    var len = orders.length;
                    startid+=len;
                    
                    if(len>=pageSize){
                       vm.showMore.history=true;
                    }else{
                       vm.showMore.history=false;
                    }
               }else{
               		vm.noMore=true;
//             		util.msg('暂无更多数据');
               }
	   	   })
	   },
	   onRouteChange:function(){
	       if(vm)vm.show=false;
	   }
	};
    return controller;
})